//
//  PeopleServiceCell.m
//  Cunli
//
//  Created by ZhanyaaLi on 15/12/7.
//  Copyright © 2015年 lilubin. All rights reserved.
//

#import "PeopleServiceCell.h"
#import "LBButton.h"
#import "UIColor+expanded.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width

@implementation PeopleServiceCell

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self setUIKit];
    [self createButtons];
}

- (void)setUIKit
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 2, 100, 21)];
    [titleLabel setText:_cellTitle];
    [titleLabel setTextColor:[UIColor colorWithHexString:@"0x333333"]];
    [titleLabel setFont:[UIFont systemFontOfSize:15]];
    [self addSubview:titleLabel];
}

- (void)createButtons
{
    CGFloat itemWidth = (kScreenWidth * 1.0 - 20) / 3;
    NSInteger count = _buttonsArray.count;
    if (count != 0) {
        for (NSInteger i = 0; i < count; i++) {
            LBButton *btn = [LBButton buttonWithType:UIButtonTypeCustom];
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
            
            CGFloat btnX = i * itemWidth;
            CGFloat btnY = 23;
            if (i > 2) {
                btnX = (i - 3) * itemWidth;
                btnY = 23 + itemWidth;
            }
            btn.frame = CGRectMake(btnX+10, btnY, itemWidth, itemWidth);
            btn.btnModel = _buttonsArray[i];
            [btn setTitleColor:[UIColor colorWithHexString:@"0x333333"] forState:UIControlStateNormal];
        }
    }
}

- (void)btnClick:(LBButton *)button
{
    _LBBtnClicked(button.btnModel.btnType);
}

@end
